<?php

namespace App\Constants;

/**
 * 操作类型枚举
 * 定义各种系统操作类型
 */
class OperationTypeEnum extends AbstractEnum
{
    // 操作类型常量
    public const CREATE = 'create';
    public const READ = 'read';
    public const UPDATE = 'update';
    public const DELETE = 'delete';
    public const LOGIN = 'login';
    public const LOGOUT = 'logout';
    public const UPLOAD = 'upload';
    public const DOWNLOAD = 'download';
    public const EXPORT = 'export';
    public const IMPORT = 'import';
    public const APPROVE = 'approve';
    public const REJECT = 'reject';
    public const TRANSFER = 'transfer';
    public const AUDIT = 'audit';

    /**
     * 获取所有枚举实例
     */
    public static function getAll(): array
    {
        return [
            new self('create', '创建', '创建新记录', '#28A745', 'plus', 1),
            new self('read', '查看', '查看记录', '#17A2B8', 'eye', 2),
            new self('update', '更新', '修改记录', '#FFC107', 'edit', 3),
            new self('delete', '删除', '删除记录', '#DC3545', 'trash', 4),
            new self('login', '登录', '用户登录', '#28A745', 'sign-in-alt', 5),
            new self('logout', '登出', '用户登出', '#6C757D', 'sign-out-alt', 6),
            new self('upload', '上传', '文件上传', '#20C997', 'upload', 7),
            new self('download', '下载', '文件下载', '#17A2B8', 'download', 8),
            new self('export', '导出', '数据导出', '#FD7E14', 'file-export', 9),
            new self('import', '导入', '数据导入', '#E83E8C', 'file-import', 10),
            new self('approve', '审批', '审批操作', '#28A745', 'check', 11),
            new self('reject', '驳回', '驳回操作', '#DC3545', 'times', 12),
            new self('transfer', '转移', '数据转移', '#6F42C1', 'exchange-alt', 13),
            new self('audit', '审计', '审计操作', '#FFA500', 'search', 14),
        ];
    }

    /**
     * 获取CRUD操作类型
     */
    public static function getCrudOperations(): array
    {
        return [
            self::CREATE,
            self::READ,
            self::UPDATE,
            self::DELETE,
        ];
    }

    /**
     * 获取文件操作类型
     */
    public static function getFileOperations(): array
    {
        return [
            self::UPLOAD,
            self::DOWNLOAD,
            self::EXPORT,
            self::IMPORT,
        ];
    }

    /**
     * 获取认证操作类型
     */
    public static function getAuthOperations(): array
    {
        return [
            self::LOGIN,
            self::LOGOUT,
        ];
    }

    /**
     * 获取审批操作类型
     */
    public static function getApprovalOperations(): array
    {
        return [
            self::APPROVE,
            self::REJECT,
            self::AUDIT,
        ];
    }

    /**
     * 检查是否为CRUD操作
     */
    public static function isCrudOperation(string $type): bool
    {
        return in_array($type, self::getCrudOperations());
    }

    /**
     * 检查是否为文件操作
     */
    public static function isFileOperation(string $type): bool
    {
        return in_array($type, self::getFileOperations());
    }

    /**
     * 检查是否为认证操作
     */
    public static function isAuthOperation(string $type): bool
    {
        return in_array($type, self::getAuthOperations());
    }

    /**
     * 检查是否为审批操作
     */
    public static function isApprovalOperation(string $type): bool
    {
        return in_array($type, self::getApprovalOperations());
    }
}
